<template>
  <div class="order-commit">
    <div class="class-header">
      <div class="header-nav">
        <div class="header-nav-left">
          <router-link to="/">
            <img
              src="../img/logo.png"
              alt
            >
            <span>80教育商城</span>
          </router-link>
        </div>
        <div class="header-nav-right">
          <ul class="header-nav-right-list">
            <li>
              <i class="iconfont icon-search"></i>
            </li>
            <li>
              <span class="search">搜索</span>
            </li>
            <li>
              <span>会员中心</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="order-commit-list-wp">
      <div class="address-wp">
        <div class="order-info">
          <span class="iconfont icon-enter"></span>
          <div class="order-info-person">
            <span>收货人：</span>
            <span>张先生</span>
          </div>
          <div class="default-icon">
            <span>默认</span>
          </div>
          <div class="order-info-phone">
            18566477290
          </div>
        </div>
        <div class="order-pos">
          <span class="iconfont icon-coordinates"></span>
          <span>河北省保定市涿州开发区</span>
        </div>
      </div>
      <div class="backpic"></div>
      <div>
        <div
          class="order-commit-list"
          v-for="(lists,index) in list"
          :key='index'
        >
          <div class="order-commit-img">
            <img
              src="../img/book1.jpg"
              alt
            >
          </div>
          <div class="order-commit-listInfo">
            <div class="order-commit-bookname">
              <span>{{lists.goodsname}}</span>
            </div>
            <div class="order-commit-bookparam">
              <div class="single-price">
                ￥{{lists.price}}
              </div>
              <div class="order-commit-bookprice">&times; {{lists.num}}</div>
            </div>
          </div>
        </div>
      </div>
      <div style="height:10px;background:#f7f7f7"></div>
      <div class="goods-prices">
          <span class="goods-prices-left">商品金额</span>
          <span class="goods-prices-right">￥{{totalPrice}}</span>
      </div>
      <div class="goods-prices">
          <span class="goods-prices-left">配送方式</span>
          <span class="goods-prices-right" style="color:#333;">
            <span>百世包邮</span>
            <span>￥0.0</span>
            <span class="iconfont icon-enter" style="color:#cdc"></span>
          </span>
      </div>
      <div class="goods-prices" style="border:none">
          <span class="goods-prices-left">支付方式</span>
          <span class="goods-prices-right">
            <span style="color:#333;">支付宝</span>
            <span></span>
            <span class="iconfont icon-enter" style="color:#cdc"></span>
          </span>
      </div>
      <div style="height:12px;background:#f7f7f7"></div>
      <div class="goods-prices" style="border:none">
          <span class="goods-prices-left">买家留言</span>
          <input type="text" placeholder="给卖家留言" v-model="liuyan">
      </div>
      <div style="height:20px;background:#f7f7f7"></div>
    </div>

    <div class="order-commit-bottom">
      <div class="order-commit-total-wp">
        <div>
          <span class="order-commit-total-text">总计：</span>
          <span class="order-commit-total-price">￥{{totalPrice}}</span>
        </div>
      </div>
      <div class="order-commit-paybtn">
        <button @click="commitFn">
          提交订单
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import session from "../util/session";
import { createNamespacedHelpers } from "vuex";
const { mapState, mapMutations, mapActions } = createNamespacedHelpers(
  "ordercommit"
);
export default {
  data() {
    return {
      totalPrice: "0",
      list:[],
      liuyan:'',
      deleteId:''
    };
  },
  methods: {
    ...mapActions(["getlist",'deleteList','postOrder']),
    commitFn(){
        let obj = {}
        obj.list = this.list
        obj.liuyan = this.liuyan
        this.postOrder({uid:session.get().id,obj:JSON.stringify(obj)}).then(()=>{
          alert('订单提交成功！')
          this.deleteList(this.deleteId)
        })
    }

  },
  mounted() {
    // console.log(this.$route.params.id)
    this.getlist().then(data=>{
      let goodsid = this.$route.params.id
      let arr = []
      let price = 0
      this.deleteId = goodsid.join(',')
      this.deleteList(this.deleteId)
        for(var i=0;i<goodsid.length;i++){
            for(var j=0;j<data.length;j++){
              if(goodsid[i] == data[j].id){
                  arr.push(data[j])
                  price += data[j].price*data[j].num
              }
            }
        }
        this.totalPrice = price
        this.list = arr
        // this.deleteId = arr[0].id
    })
  }
};
</script>

<style scoped>
.goods-prices{
  margin: 0 15px;
  border-bottom: 1px solid #f2f2f2;
  font-size: 12px;
  height: 50px;
  line-height: 50px;
  color: #333;
}
.goods-prices input{
  padding-left: 8px;
  border: none;
  background: 0 0;
  font-size: 12px;
  color: #999;
  max-width: 190px;
  width: auto;
  height: 30px;
  outline: none;
}
.goods-prices span{
  display: inline-block;
  vertical-align: middle;
}
.goods-prices-right{
  display: block;
  float: right;
  height: 50px;
  overflow: hidden;
  color: #3285ff;
}
.goods-prices-left{
  margin: 0 10px;
}
.backpic {
  width: 100%;
  height: 5px;
  background: url(../img/shipTopBg.jpg);
  background-size: 100% 100%;
  background-position: 0 0;
}
.order-pos {
  position: relative;
  left: -5px;
}
.order-pos span {
  display: inline-block;
  vertical-align: middle;
}
.order-pos .icon-coordinates {
  font-size: 25px;
  color: #999;
}
.default-icon {
  float: right;
  line-height: 54px;
  margin: 0 0 0 6px;
  color: #fff;
  text-align: center;
  font-size: 7px;
}
.default-icon span {
  display: inline-block;
  width: 30px;
  height: 15px;
  line-height: 15px;
  border-radius: 2px;
  background-color: #3285ff;
}
.order-info-phone {
  float: right;
  display: inline-block;
  height: 100%;
  line-height: 54px;
  margin-right: 6px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.order-info-person {
  float: left;
  display: block;
  width: 46%;
  margin-right: 0;
  padding-left: 0;
  text-align: left;
  line-height: 54px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.order-info {
  height: 40px;
  line-height: 40px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  padding-right: 16px;
  position: relative;
}
.order-info .icon-enter {
  position: absolute;
  right: -2px;
  top: 5px;
  font-size: 17px;
  vertical-align: middle;
  line-height: 45px;
  color: #666;
}
.address-wp {
  padding: 0 9px 8px 17px;
  color: #333;
  font-size: 12px;
  background: #f5f5f5;
}
.order-commit {
  max-width: 768px;
  margin-bottom: 50px;
}
.order-commit-bottom {
  position: fixed;
  bottom: 0;
  height: 50px;
  width: 100%;
  max-width: 768px;
  font-size: 15px;
  z-index: 11;
  border-top: 1px solid #ebebeb;
  background-color: #fff;
  display: flex;
}
.order-commit-bottom > div {
  flex-grow: 1;
}
.order-commit-total-wp {
  font-size: 14px;
  color: #333;
  height: 100%;
  line-height: 48px;
  padding-left: 10px;
}
.order-commit-total-wp .order-commit-total-price {
  color: #3285ff;
}
.order-commit-paybtn {
  text-align: right;
}
.order-commit-paybtn button {
  width: 90px;
  height: 100%;
  background-color: #fff;
  border: none;
  background: -webkit-gradient(
    linear,
    left top,
    right top,
    from(#56c4e7),
    to(#3285ff)
  );
  outline: none;
  font-size: 13px;
  color: #fff;
}
.order-commit-list-wp {
  background-color: #fff;
}
.order-commit-list {
  display: -webkit-box;
  background: #fafafa;
  padding: 15px;
  margin: 10px 0;
}
.order-commit-img {
  width: 75px;
  height: 75px;
}
.order-commit-img img {
  width: 100%;
  height: 100%;
}
.order-commit-listInfo {
  flex-grow: 1;
  padding-left: 14px;
}
.order-commit-bookname {
  font-size: 13px;
  color: #333;
  position: relative;
}
.order-commit-bookname span {
  height: 16px;
  line-height: 16px;
  margin-right: 5px;
  font-size: 13px;
  color: #666;
  word-break: break-all;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.order-commit-bookparam {
  display: flex;
  margin-top: 40px;
  position: relative;
}
.order-commit-bookparam > div span {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 1px solid #eee;
  vertical-align: middle;
  text-align: center;
  line-height: 20px;
  color: #949494;
}
.order-commit-bookparam input {
  width: 30px;
  height: 24px;
  outline: none;
  vertical-align: middle;
  text-align: center;
  border: none;
}
.order-commit-bookprice {
  color: #333;
  font-size: 12px;
  float: right;
  width: 38%;
  text-align: right;
  position: absolute;
  top: 6px;
  right: 4px;
}
.single-price {
  font-size: 12px;
  color: #3285ff;
}
</style>
